//
//  StatusCellTopView.swift
//  WeoboWithSteveLi
//
//  Created by SteveLi on 2017/10/6.
//  Copyright © 2017年 李军桦. All rights reserved.
//

import UIKit


/// 顶部视图
class StatusCellTopView: UIView {
    
    /// 微博视图模型
    var viewModel: StatusViewModel? {
        didSet {
            //姓名
            nameLabel.text = viewModel?.status.user?.screen_name
            //头像      
            iconView.setImageWith((viewModel?.userProfileUrl)!, placeholderImage: viewModel?.userDefaultIconView)
            //会员图标
            memberIconView.image = viewModel?.userMemberImage
            //认证图标
            vipIconView.image = viewModel?.userVipImage
            //TODO - 后面补充
            //时间
            timeLabel.text = "刚刚" //viewModel?.status.created_at
            sourceLabel.text = "来自川信" //viewModel?.status.source
        }
    }
    //MARK: - 构造函数
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //MARK: -懒加载控件
    /// 头像
    lazy var iconView: UIImageView = UIImageView(imageName: "avatar_default_big")
    /// 姓名
    lazy var nameLabel: UILabel = UILabel(title: "王老五", fontSize: 14)
    /// 会员图标
    lazy var memberIconView: UIImageView = UIImageView(imageName: "common_icon_membership_level1")
    /// 认证图标
    lazy var vipIconView: UIImageView = UIImageView(imageName: "avatar_vip")
    /// 时间标签
    lazy var timeLabel: UILabel = UILabel(title: "现在", fontSize: 11, color: UIColor.orange)
    /// 来源标签
    lazy var sourceLabel: UILabel = UILabel(title: "来源", fontSize: 11)
    
}


//MARK: - 设置界面
extension StatusCellTopView {
  fileprivate  func setupUI() {
        //backgroundColor = UIColor(white: 0.95, alpha: 1.0)
        backgroundColor = UIColor.white
        //0.添加分隔视图
        let sepView = UIView()
       // sepView.backgroundColor = UIColor.lightGray
        addSubview(sepView)
        
        //1.添加控件
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(memberIconView)
        addSubview(vipIconView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        //2.自动布局
        sepView.snp.makeConstraints { (make) in
            make.top.equalTo(self.snp.top)
            make.left.equalTo(self.snp.left)
            make.right.equalTo(self.snp.right)
            make.height.equalTo(StatusCellMargin)
        }
        
        iconView.snp.makeConstraints { (make) in
            make.top.equalTo(sepView.snp.bottom).offset(StatusCellMargin)
            make.left.equalTo(self.snp.left).offset(StatusCellMargin)
            make.width.equalTo(StatusCellIconWidth)
            make.height.equalTo(StatusCellIconWidth)
        }
        nameLabel.snp.makeConstraints { (make) in
            make.top.equalTo(iconView.snp.top)
            make.left.equalTo(iconView.snp.right).offset(StatusCellMargin)
        }
        memberIconView.snp.makeConstraints { (make) in
            make.top.equalTo(nameLabel.snp.top)
            make.left.equalTo(nameLabel.snp.right).offset(StatusCellMargin)
        }
        vipIconView.snp.makeConstraints { (make) in
            make.centerX.equalTo(iconView.snp.right)
            make.centerY.equalTo(iconView.snp.bottom)
        }
        timeLabel.snp.makeConstraints { (make) in
            make.bottom.equalTo(iconView.snp.bottom)
            make.left.equalTo(iconView.snp.right).offset(StatusCellMargin)
        }
        sourceLabel.snp.makeConstraints { (make) in
            make.bottom.equalTo(iconView.snp.bottom)
            make.left.equalTo(timeLabel.snp.right).offset(StatusCellMargin)
        }
        
    }

}
